#ifndef SHOP_HPP
#define SHOP_HPP

/*******************************************************************************
 ** Name: shop.hpp                                                       **
 ** Description:                                                              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 **  Copyright (c) 2009-2011 B "Gian" James  <soap@government-sanctioned.us>  **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  Redistribution and use in source and binary forms, with or without       **
 **  modification, are permitted provided that the following conditions are   **
 **  met:                                                                     **
 **                                                                           **
 **  * Redistributions of source code must retain the above copyright notice, **
 **    this list of conditions and the following disclaimer.                  **
 **  * Redistributions in binary form must reproduce the above copyright      **
 **    notice, this list of conditions and the following disclaimer in the    **
 **    documentation and/or other materials provided with the distribution.   **
 **                                                                           **
 **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      **
 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED **
 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           **
 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT        **
 ** HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    **
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  **
 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    **
 ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    **
 ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      **
 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        **
 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              **
 **                                                                           **
 ******************************************************************************/
// Modified $Date: 2011-10-22 02:09:07 +0000 (Sat, 22 Oct 2011) $ by $Author: gian.james $
#define shop_hpp_ID   "$Id: shop.hpp 146 2011-10-22 02:09:07Z gian.james $"

#include "container.hpp"
#include "weapon.hpp"
#include "item.hpp"
#include "magic.hpp"
#include "Range.hpp"
#include "economy.hpp"

#define DEFAULT_SELL_PROFIT	1.5		// 150%
#define DEFAULT_BUY_PROFIT	0.7		// 70%
#define DEFAULT_GOLD_MULT	100000	// 100k * caliber

//! Condensed item struct for shop goods
struct ShopGoods
{
	id_t	itemID;	// from DB
	std::string name;
};

class Employee
{
public:
	id_t &	NPC() { return npc; }
	double & Pay() { return pay; }
	std::string & Position() { return position; }

private:
	id_t	npc;
	double	pay;	// monthly pay
	std::string position;
};

//! @class Shop
//! @brief Basic business shop class
class Shop : public Room
{
public:
	Shop();

	std::string & Name() { return name; }
	size_t &	MarketValue() { return marketValue; }
	id_t &		Stock() { return stock; }
	size_t &	StockIssued() { return stockIssued; }
	id_t &		Loan() { return loan; }
	id_t &		Bonds() { return bonds; }
	CreditRating & CreditScore() { return creditRating; }

	// Getters
	id_t		ShopKeeper() { return shopKeeper; }
	WpnType *	WeaponTypes() { return buyWpnType; }
	MType *		MagickTypes() { return buyMagickType; }
	ItemType *	ItemTypes() { return buyItemType; }
	AmmoType *	AmmoTypes() { return buyAmmoType; }
	int			SellProfit() { return sellProfit; }
	int			BuyProfit() { return buyProfit; }
	Range *		Hours() { return hours; }
	uint8_t		Caliber() { return caliber; }

	// Setters
	void		ShopKeeper(id_t i) { shopKeeper = i; }
	void		WeaponTypes(WpnType w);
	void		MagickTypes(MType );
	void		ItemTypes(ItemType);
	void		AmmoTypes(AmmoType);
	void		SellProfit(int s) { sellProfit = s; }
	void		BuyProfit(int s) { buyProfit = s; }
	void		Hours(int open, int close);
	void		Caliber(uint8_t c) { caliber = c; }

	void		Buy(WorldObject *);
	void		Sell(WorldObject *);


protected:
	id_t		shopKeeper;
	std::string	name;
	WpnType	*	buyWpnType;
	MType	*	buyMagickType;
	ItemType*	buyItemType;
	AmmoType*	buyAmmoType;
	int			sellProfit;
	int			buyProfit;
	Range	*	hours;
	uint8_t		caliber;	//!< caliber of store. determines how much $$ onhand
	size_t		scratch;
	std::list<ShopGoods> inventory;
	std::list<Employee> employees;
	size_t		marketValue;
	id_t		stock;		// idstock from DB
	size_t		stockIssued;	// number of stocks issued
	id_t		loan;		// any loan taken out
	id_t		bonds;		// bonds issued
	CreditRating creditRating;
};

//! @class Bank
//! @brief The derived class for player-ran banking
class Bank : public Room
{
public:

private:
	id_t		owner;
	id_t		fcbaID;	// fcbaID from db certificate
	size_t		reserve;
};

#endif /* SHOP_HPP */
